package content;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;

import javax.swing.*;
import javax.swing.event.ListDataListener;

import stats.Equips;
import stats.Profile;
import stats.CharStat.Asura;
import stats.CharStat.Deva;
import stats.CharStat.Gaia;

import eventConfig.*;
import content.IOManage;

public class GUIContent {
	
	public static class GUIMenu{
		
		private JMenuBar makeMenu(){
	
		
			
		JMenu menuFile = new JMenu("File");
		JMenu menuEdit = new JMenu("Edit");
		JMenu menuHelp = new JMenu("Help");
		final JMenuItem menuFileNew = new JMenuItem("New");
		final JMenuItem menuFileLoad = new JMenuItem("Load Profile...");
		final JMenuItem menuFileSave = new JMenuItem("Save Profile...");
		final JMenuItem menuEditReset = new JMenuItem("Reset");
		final JMenuItem menuHelpAbout = new JMenuItem("About");
		JMenuBar menuBar = new JMenuBar();
		
		class menuListener extends MouseEventSetUp{
			public void leftButtonPressed(MouseEvent mouseEvent){
				if (mouseEvent.getSource() == menuFileNew){
					System.out.println("New");				
				}
				if (mouseEvent.getSource() == menuFileLoad){
					System.out.println("Load");
					File f = FileLoader.openFile(menuFileSave);
					IOManage.loadFile(f);
				} 
				if (mouseEvent.getSource() == menuFileSave){
					System.out.println("Save");
					File f = FileLoader.writeFile(menuFileSave);
					IOManage.saveFile(f);
				} 
				if (mouseEvent.getSource() == menuEditReset){
					System.out.println("Reset");
				}
				if (mouseEvent.getSource()== menuHelpAbout){
					System.out.println("About");
				}
			}
		}
		
		menuFileNew.addMouseListener(new menuListener());
		menuFileLoad.addMouseListener(new menuListener());
		menuFileSave.addMouseListener(new menuListener());
		menuEditReset.addMouseListener(new menuListener());
		menuHelpAbout.addMouseListener(new menuListener());
		
		menuFile.add(menuFileNew);
		menuFile.add(menuFileLoad);
		menuFile.add(menuFileSave);
		menuEdit.add(menuEditReset);
		menuHelp.add(menuHelpAbout);
		
		menuBar.add(menuFile);
		menuBar.add(menuEdit);
		menuBar.add(menuHelp);
		
		return menuBar;
		}
		
		public JMenuBar getMenu(){
			return makeMenu();
		}
		
	}

	public static class GUIPanel{
		
		//use threading to show right pane...use event catcher to update, and then forward that event
		//to where it was intended to go to.
		
		private Profile profile = null;

		public Profile getProfile(){
			return profile;
		}
		
		private class PlayerTab extends JPanel{
			
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 6106184247038677293L;
			
			private PlayerStats toUpdate = null;

			public void setName(JTextField component){
				String name = "";
				//name = component.getText(0, Math.min(0, (component.getText().length())));
				name = component.getText();
				profile.setName(name);
				System.out.println(profile.getName());
				toUpdate.updateText();
				return;
			}
			
			class PlayerNameListener implements ActionListener{

				private JTextField text = null;
				
				PlayerNameListener(JTextField text){
					this.text = text;
				}
				
				public void actionPerformed(ActionEvent arg0) {
					setName(text);
					toUpdate.updateText();
				}
			}
			
			
			class PlayerNameFocusListener implements FocusListener{

				private JTextField text = null; 
				PlayerNameFocusListener(JTextField text){
					this.text = text;
				}
				
				public void focusGained(FocusEvent arg0){
				}

				public void focusLost(FocusEvent arg0) {
					System.out.println("here");
					setName(text);
					toUpdate.updateText();
				}
			}
			
			class PlayerComboListener implements ItemListener{

				private JComboBox comp = null;
				
				PlayerComboListener(JComboBox comp){
					this.comp = comp;
				}
				
				public void itemStateChanged(ItemEvent arg0){
					if (comp.getName().equals("playerJobLevelBox")){
						profile.setJLevel(Integer.valueOf((String) comp.getSelectedItem()));
						toUpdate.updateText();
						return;
					} else if (comp.getName().equals("playerJobBox")){
						String selected = (String) comp.getSelectedItem();
						for (Asura s: Asura.values()){
							if (selected.equals(s.toString())){
								profile.setJob(s);
								toUpdate.updateText();
								return;
							}
						}
						for (Deva s: Deva.values()){
							if (selected.equals(s.toString())){
								profile.setJob(s);
								toUpdate.updateText();
								return;
							}
						}
						for (Gaia s: Gaia.values()){
							if (selected.equals(s.toString())){
								profile.setJob(s);
								toUpdate.updateText();
								return;
							}
						}
					} else if (comp.getName().equals("playerLevelBox")){
						profile.setLevel(Integer.valueOf((String) comp.getSelectedItem()));
						toUpdate.updateText();
						return;
					}
				}
			}
			
			PlayerTab(Profile profile, PlayerStats toUpdate){
			//TODO add belt pet
			
				this.toUpdate = toUpdate; 
				
			String[] levelList = new String[stats.Profile.MAXLEVEL];
			for(int i=0; i<levelList.length; i++){
				levelList[i] = String.valueOf(i+1);
			}
			String[] jobList = new String[Asura.values().length + 
			                              Deva.values().length +
			                              Gaia.values().length];
			int pos = 0;
			for(Asura jb:stats.CharStat.Asura.values()){
				jobList[pos] = jb.toString();
				pos++;
			}
			for(Deva jb:stats.CharStat.Deva.values()){
				jobList[pos] = jb.toString();
				pos++;
			}
			for(Gaia jb:stats.CharStat.Gaia.values()){
				jobList[pos] = jb.toString();
				pos++;
			}
			String[] jobLevel = null;
			jobLevel = new String[Profile.getTable(profile.getJob()).size()];
			for(int i=0; i<jobLevel.length; i++){
				jobLevel[i] = String.valueOf(i+1);
			}
			
			this.setLayout(null);
			
			JLabel playerNameLabel = new JLabel("Player Name:");
			JTextField playerNameField = new JTextField(profile.getName());
			playerNameField.addActionListener(new PlayerNameListener(playerNameField));
			playerNameField.addFocusListener(new PlayerNameFocusListener(playerNameField));
			
			JLabel playerLevel = new JLabel("Level:");
			JComboBox playerLevelBox = new JComboBox(levelList);
			playerLevelBox.setName("playerLevelBox");
			playerLevelBox.setSelectedItem(profile.getLevel());
			playerLevelBox.addItemListener(new PlayerComboListener(playerLevelBox));

			JLabel playerJob = new JLabel("Job:");
			JComboBox playerJobBox = new JComboBox(jobList);
			playerJobBox.setName("playerJobBox");
			playerJobBox.setSelectedItem(profile.getJob());
			playerJobBox.addItemListener(new PlayerComboListener(playerJobBox));
			
			JLabel playerJobLevel = new JLabel("Job Level:");
			JComboBox playerJobLevelBox = new JComboBox(jobLevel);
			playerJobLevelBox.setName("playerJobLevelBox");
			playerJobLevelBox.setSelectedItem(profile.getJLevel());
			playerJobLevelBox.addItemListener(new PlayerComboListener(playerJobLevelBox));
			
			this.add(playerNameLabel);
			this.add(playerNameField);
			this.add(playerLevel);
			this.add(playerLevelBox);
			this.add(playerJob);
			this.add(playerJobBox);
			this.add(playerJobLevel);
			this.add(playerJobLevelBox);
			
			Insets insets = this.getInsets();
			Dimension size = playerNameLabel.getPreferredSize();
			playerNameLabel.setBounds(20 + insets.left, 5 + insets.top,
			             size.width, size.height);
			size = playerNameField.getPreferredSize();
			playerNameField.setBounds(105 + insets.left, 5 + insets.top,
			             size.width+40, size.height);
			size = playerLevel.getPreferredSize();
			playerLevel.setBounds(20 + insets.left, 30 + insets.top,
			             size.width, size.height);
			playerLevelBox.setBounds(105 + insets.left, 30 + insets.top,
			             size.width+22, size.height+2);
			size = playerJob.getPreferredSize();
			playerJob.setBounds(20 + insets.left, 50 + insets.top,
			             size.width, size.height);
			size = playerJobBox.getPreferredSize();
			playerJobBox.setBounds(105 + insets.left, 50 + insets.top,
			             size.width+10, size.height);
			size = playerJobLevel.getPreferredSize();
			playerJobLevel.setBounds(20 + insets.left, 80 + insets.top,
			             size.width, size.height);
			size = playerJobLevelBox.getPreferredSize();
			playerJobLevelBox.setBounds(105 + insets.left, 80 + insets.top,
			             size.width+8, size.height);

			this.setPreferredSize(new Dimension (200, 500));
			}
		}

		public class EquipTab extends JPanel{
			
			private PlayerStats toUpdate = null;
			private ArrayList<Equips> mainArmorList = null;
			private ArrayList<Equips> mainWeaponList = null;
			private ArrayList<Equips> mainAccessoryList = null;
			
			private ArrayList<String> armorList = new ArrayList<String>();
			private ArrayList<String> helmList = new ArrayList<String>();
			private ArrayList<String> glovesList = new ArrayList<String>();
			private ArrayList<String> bootsList = new ArrayList<String>();
			private ArrayList<String> maskList = new ArrayList<String>();
			private ArrayList<String> cloakList = new ArrayList<String>();
			
			//add sheild to 1hlist
			private ArrayList<String> weapon1hList = new ArrayList<String>();
			private ArrayList<String> weapon2hList = new ArrayList<String>();
			
			private ArrayList<String> earringList = new ArrayList<String>();
			private ArrayList<String> necklaceList = new ArrayList<String>();
			private ArrayList<String> ringList = new ArrayList<String>();
			private ArrayList<String> bagList = new ArrayList<String>();
			private ArrayList<String> beltList = new ArrayList<String>();
			
			
			private ArrayList<String> stoneList = new ArrayList<String>();
			
			private String[] levelList = new String[10];
			private String[] enchantmentList = new String[21];
			
			private void getMainLists() throws IOException{
				mainArmorList = stats.FileReaderWriter.getArmorList();
				mainWeaponList = stats.FileReaderWriter.getWeaponsList();
				mainAccessoryList = stats.FileReaderWriter.getAccessoriesList();
			}
			

			
			private void setAccessories(){
				//Earring, Necklace, Ring, Bag, Belt
				for(Equips s: mainAccessoryList){
					if (s.type().equals("Earring")){
						earringList.add(s.name());
					} else if (s.type().equals("Necklace")){
						necklaceList.add(s.name());
					} else if (s.type().equals("Ring")){
						ringList.add(s.name());
					} else if (s.type().equals("Bag")){
						bagList.add(s.name());
					} else {
						beltList.add(s.name());
					}
				}
			}
			
			private void setLists(){
				setAccessories();
				for (int i=0; i<10; i++){
					levelList[i]=String.valueOf(i+1);
				}
				for (int i=0; i<21; i++){
					enchantmentList[i]=String.valueOf(i);
				}
				String[] Basic = {"+1", "+3", "+5", "+7", "+9", "+11", "+13"};
				String[] Rare = {"+3", "+5", "+7", "+9", "+12", "+15", "+18"};
				String[] Epic = {"+4", "+7", "+10", "+13", "+16", "+19", "+22"};
				
				for (int i=0; i<7; i++){
					stoneList.add("Str"+Basic[i]);
					stoneList.add("Str"+Rare[i]);
					stoneList.add("Str"+Epic[i]);
					stoneList.add("Vit"+Basic[i]);
					stoneList.add("Vit"+Rare[i]);
					stoneList.add("Vit"+Epic[i]);
					stoneList.add("Agi"+Basic[i]);
					stoneList.add("Agi"+Rare[i]);
					stoneList.add("Agi"+Epic[i]);
					stoneList.add("Int"+Basic[i]);
					stoneList.add("Int"+Rare[i]);
					stoneList.add("Int"+Epic[i]);
					stoneList.add("Wis"+Basic[i]);
					stoneList.add("Wis"+Rare[i]);
					stoneList.add("Wis"+Epic[i]);
					stoneList.add("Dex"+Basic[i]);
					stoneList.add("Dex"+Rare[i]);
					stoneList.add("Dex"+Epic[i]);
				}
			}
			
			private int getLevel(String name){
				for(Equips e: mainArmorList){
					if (e.name().equals(name)){
						return e.getLevel();
					}
				} for(Equips e: mainWeaponList){
					if (e.name().equals(name)){
						return e.getLevel();
					}
				}
				for(Equips e: mainAccessoryList){
				if (e.name().equals(name)){
					return e.getLevel();
					}
				}
				return 1;
			}
			
			private int getEnchantment(String name){
				for(Equips e: mainArmorList){
					if (e.name().equals(name)){
						return e.getEnchantment();
					}
				} for(Equips e: mainWeaponList){
					if (e.name().equals(name)){
						return e.getEnchantment();
					}
				}
				for(Equips e: mainAccessoryList){
				if (e.name().equals(name)){
					return e.getEnchantment();
					}
				}
				return 1;
			}
			
			private Equips getEquip(String name){
				for(Equips e: mainArmorList){
					if (e.name().equals(name)){
						return e;
					}
				} for(Equips e: mainWeaponList){
					if (e.name().equals(name)){
						return e;
					}
				}
				for(Equips e: mainAccessoryList){
				if (e.name().equals(name)){
					return e;
					}
				}
				return null;
			}
			
			private class CustomEquipComboBox extends JComboBox{
				/**
				 * 
				 */
				private static final long serialVersionUID = -3373794283646001669L;
				Hashtable<String, Equips> comboTable = new Hashtable<String, Equips>();
				ArrayList<String> comboList = new ArrayList<String>();
				String type;
				
				public JComboBox levelBox = new JComboBox(levelList);
				public JComboBox enchantBox = new JComboBox(enchantmentList);
				public JComboBox stoneBox1 = new JComboBox(stoneList.toArray());
				public JComboBox stoneBox2 = new JComboBox(stoneList.toArray());
				public JComboBox stoneBox3 = new JComboBox(stoneList.toArray());
				public JComboBox stoneBox4 = new JComboBox(stoneList.toArray());
				
				//(Armor/Equip/Acc List, Type of Equipment)
				CustomEquipComboBox(ArrayList<Equips> list, String type, final PlayerStats toUpdate){
					super();
					this.type = type;
					makeList(list);
					for(Object s:comboList.toArray()){
						this.addItem(s.toString());
					}
					this.setSelectedIndex(-1);
					if(comboList.size() > 0){
						this.setSelectedIndex(0);
						addEquip(comboTable.get(comboList.get(0)));
					}
					
					levelBox.setSelectedIndex(this.getLevel()-1);
					enchantBox.setSelectedIndex(this.getEnchant());
					
					
					this.addItemListener(new ItemListener(){
						public void itemStateChanged(ItemEvent arg0) {
							addEquip(comboTable.get(arg0.getItem()));
							levelBox.setSelectedIndex(getLevel()-1);
							enchantBox.setSelectedIndex(getEnchant());
							toUpdate.updateText();
						}
					});
					
					levelBox.addItemListener(new ItemListener(){
						public void itemStateChanged(ItemEvent arg0){
							setLevel(Integer.valueOf((String) arg0.getItem()));
							toUpdate.updateText();
						}
					});
					
					enchantBox.addItemListener(new ItemListener(){
						public void itemStateChanged(ItemEvent arg0){
							setEnchant(Integer.valueOf((String) arg0.getItem()));
							toUpdate.updateText();
						}
					});
					
					stoneBox1.addItemListener(new ItemListener(){
						public void itemStateChanged(ItemEvent arg0){
							System.out.println("here");
							if(arg0.getStateChange() == ItemEvent.SELECTED){
								System.out.println("changed");
								setStone((String) arg0.getItem(), 0);
								toUpdate.updateText();
							}
						}
					});
					
					stoneBox2.addItemListener(new ItemListener(){
						public void itemStateChanged(ItemEvent arg0){
							setStone((String) arg0.getItem(), 1);
							toUpdate.updateText();
						}
					});
					
					stoneBox3.addItemListener(new ItemListener(){
						public void itemStateChanged(ItemEvent arg0){
							setStone((String) arg0.getItem(), 2);
							toUpdate.updateText();
						}
					});
					
					stoneBox4.addItemListener(new ItemListener(){
						public void itemStateChanged(ItemEvent arg0){
							setStone((String) arg0.getItem(), 3);
							toUpdate.updateText();
						}
					});
					
				}
				
				
				private void makeWeapon1hList(){
					for(Equips s: mainArmorList){
						if (s.type().equals("Shield")){
							comboList.add(s.name());
							comboTable.put(s.name(), s);
							}
						}
					for(Equips s: mainWeaponList){
						if (s.type().contains("1h") || s.type().equals("Dagger")){
							comboList.add(s.name());
							comboTable.put(s.name(), s);
						}
					}
				}
				
				private void makeWeapon2hList(){
					//Axe1h, Axe2h, Bow2h, CrossBow2h, Dagger, Blunt1h,
					//Blunt2h, Spear2h, Staff1h, Staff2h, Sword1h, Sword2h
					for(Equips s: mainWeaponList){
						if (s.type().contains("1h") || s.type().equals("Dagger")){
							comboList.add(s.name());
							comboTable.put(s.name(), s);
						} else {
							comboTable.put(s.name(), s);
						}
					}
				}
				
				private void makeList(ArrayList<Equips> originalList){
					
					if(type.equals("Weapon")){
						makeWeapon2hList();
					} else if(type.equals("Weapon1h")){
						makeWeapon1hList();
					}
					
					for (Equips e:originalList){
						if (e.type().equals(type)){
							comboList.add(e.name());
							comboTable.put(e.name(), e);
						}
					}
				}
				
				private void addEquip(Equips equip){
					profile.addEquip(equip);
				}
				
				private void setLevel(int level){
					comboTable.get(this.getSelectedItem()).setLevel(level);
					addEquip(comboTable.get(this.getSelectedItem()));
				}
				
				public int getLevel(){
					return comboTable.get(this.getSelectedItem()).getLevel();
				}
				
				private void setEnchant(int enchant){
					comboTable.get(this.getSelectedItem()).setEnchantment(enchant);
					addEquip(comboTable.get(this.getSelectedItem()));
				}
				
				public int getEnchant(){
					return comboTable.get(this.getSelectedItem()).getEnchantment();
				}
				
				private void setStone(String stat, int pos){
					String[] splitStat = stat.split("[+]");
					comboTable.get(this.getSelectedItem()).addStones(splitStat[0], Integer.valueOf(splitStat[1]), pos);
					addEquip(comboTable.get(this.getSelectedItem()));
				}
				
			}
			
			
			EquipTab(Profile player, PlayerStats toUpdate) throws IOException{
				this.toUpdate = toUpdate;
				getMainLists();
				setLists();
				
				JLabel levelLabel = new JLabel("Level");
				JLabel enchantmentLabel = new JLabel("Enchantment");
				JLabel stone1Label = new JLabel("Stone 1");
				JLabel stone2Label = new JLabel("Stone 2");
				JLabel stone3Label = new JLabel("Stone 3");
				JLabel stone4Label = new JLabel("Stone 4");
				
				JLabel helmLabel = new JLabel("Helmet: ");
				CustomEquipComboBox helmBox = new CustomEquipComboBox(mainArmorList, "Helmet", toUpdate);
				JComboBox helmLevelBox = helmBox.levelBox;
				JComboBox helmEnchantBox = helmBox.enchantBox;
				JComboBox helmStoneBox1 = helmBox.stoneBox1;
				JComboBox helmStoneBox2 = helmBox.stoneBox2;
				
				JLabel maskLabel = new JLabel("Mask: ");
				CustomEquipComboBox maskBox = new CustomEquipComboBox(mainArmorList, "Mask", toUpdate);
				JLabel armorLabel = new JLabel("Armor: ");
				CustomEquipComboBox armorBox = new CustomEquipComboBox(mainArmorList, "Armor", toUpdate);
				JLabel cloakLabel = new JLabel("Cloak: ");
				CustomEquipComboBox cloakBox = new CustomEquipComboBox(mainArmorList, "Cloak", toUpdate);
				JLabel glovesLabel = new JLabel("Gloves: ");
				CustomEquipComboBox glovesBox = new CustomEquipComboBox(mainArmorList, "Gloves", toUpdate);
				JLabel bootsLabel = new JLabel("Boots: ");
				CustomEquipComboBox bootsBox = new CustomEquipComboBox(mainArmorList, "Boots", toUpdate);
				JLabel weaponLabel = new JLabel("Weapon: ");
				CustomEquipComboBox weaponBox = new CustomEquipComboBox(mainWeaponList, "Weapon", toUpdate);
				JLabel shieldLabel = new JLabel("Shield: ");
				CustomEquipComboBox shieldBox = new CustomEquipComboBox(mainWeaponList, "Weapon1h", toUpdate);
				
				JLabel necklaceLabel = new JLabel("Necklace: ");
				CustomEquipComboBox necklaceBox = new CustomEquipComboBox(mainAccessoryList, "Necklace", toUpdate);
				JLabel earringLabel = new JLabel("Earrings: ");
				CustomEquipComboBox earringBox = new CustomEquipComboBox(mainAccessoryList, "Earring", toUpdate);
				JLabel ring1Label = new JLabel("Ring1: ");
				CustomEquipComboBox ring1Box = new CustomEquipComboBox(mainAccessoryList, "Ring", toUpdate);
				JLabel ring2Label = new JLabel("Ring2: ");
				CustomEquipComboBox ring2Box = new CustomEquipComboBox(mainAccessoryList, "Ring", toUpdate);
				
				GroupLayout layout = new GroupLayout(this);
				this.setLayout(layout);
				
				layout.setAutoCreateGaps(true);
				layout.setAutoCreateContainerGaps(false);
				
				GroupLayout.SequentialGroup horizontalSeqGrp1 = layout.createSequentialGroup();  
				GroupLayout.SequentialGroup verticalSeqGrp1 = layout.createSequentialGroup();
				
				GroupLayout.ParallelGroup hParallelGroup1 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);  
				GroupLayout.ParallelGroup hParallelGroup2 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
				GroupLayout.ParallelGroup hParallelGroup3 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
				GroupLayout.ParallelGroup hParallelGroup4 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
				GroupLayout.ParallelGroup hParallelGroup5 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
				GroupLayout.ParallelGroup hParallelGroup6 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
				GroupLayout.ParallelGroup hParallelGroup7 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
				GroupLayout.ParallelGroup hParallelGroup8 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
				
				hParallelGroup1.addComponent(helmLabel);
				hParallelGroup1.addComponent(maskLabel);
				hParallelGroup1.addComponent(armorLabel);
				hParallelGroup1.addComponent(cloakLabel);
				hParallelGroup1.addComponent(glovesLabel);
				hParallelGroup1.addComponent(bootsLabel);
				hParallelGroup1.addComponent(weaponLabel);
				hParallelGroup1.addComponent(shieldLabel);
				hParallelGroup1.addComponent(necklaceLabel);
				hParallelGroup1.addComponent(earringLabel);
				hParallelGroup1.addComponent(ring1Label);
				hParallelGroup1.addComponent(ring2Label);
				hParallelGroup2.addComponent(helmBox);
				hParallelGroup2.addComponent(maskBox);
				hParallelGroup2.addComponent(armorBox);
				hParallelGroup2.addComponent(cloakBox);
				hParallelGroup2.addComponent(glovesBox);
				hParallelGroup2.addComponent(bootsBox);
				hParallelGroup2.addComponent(weaponBox);
				hParallelGroup2.addComponent(shieldBox);
				hParallelGroup2.addComponent(necklaceBox);
				hParallelGroup2.addComponent(earringBox);
				hParallelGroup2.addComponent(ring1Box);
				hParallelGroup2.addComponent(ring2Box);
				hParallelGroup3.addComponent(levelLabel);
				hParallelGroup3.addComponent(helmLevelBox);
				hParallelGroup4.addComponent(enchantmentLabel);
				hParallelGroup4.addComponent(helmEnchantBox);
				hParallelGroup5.addComponent(stone1Label);
				hParallelGroup5.addComponent(helmStoneBox1);
				hParallelGroup6.addComponent(stone2Label);
				hParallelGroup6.addComponent(helmStoneBox2);
				hParallelGroup7.addComponent(stone3Label);
				hParallelGroup8.addComponent(stone4Label);
				
				horizontalSeqGrp1.addGroup(hParallelGroup1);  
				horizontalSeqGrp1.addGroup(hParallelGroup2);
				horizontalSeqGrp1.addGroup(hParallelGroup3);
				horizontalSeqGrp1.addGroup(hParallelGroup4);
				horizontalSeqGrp1.addGroup(hParallelGroup5);
				horizontalSeqGrp1.addGroup(hParallelGroup6);
				horizontalSeqGrp1.addGroup(hParallelGroup7);
				horizontalSeqGrp1.addGroup(hParallelGroup8);
				
				GroupLayout.ParallelGroup vparallelGroup0 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup1 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup2 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup3 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup4 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup5 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup6 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup7 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup8 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup9 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup10 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup11 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				GroupLayout.ParallelGroup vparallelGroup12 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
				
				vparallelGroup0.addComponent(levelLabel);
				vparallelGroup0.addComponent(enchantmentLabel);
				vparallelGroup0.addComponent(stone1Label);
				vparallelGroup0.addComponent(stone2Label);
				vparallelGroup0.addComponent(stone3Label);
				vparallelGroup0.addComponent(stone4Label);
				vparallelGroup1.addComponent(helmLabel);
				vparallelGroup1.addComponent(helmBox);
				vparallelGroup1.addComponent(helmLevelBox);
				vparallelGroup1.addComponent(helmEnchantBox);
				vparallelGroup1.addComponent(helmStoneBox1);
				vparallelGroup1.addComponent(helmStoneBox2);
				vparallelGroup2.addComponent(maskLabel);
				vparallelGroup2.addComponent(maskBox);
				vparallelGroup3.addComponent(armorLabel);
				vparallelGroup3.addComponent(armorBox);
				vparallelGroup4.addComponent(cloakLabel);
				vparallelGroup4.addComponent(cloakBox);
				vparallelGroup5.addComponent(glovesLabel);
				vparallelGroup5.addComponent(glovesBox);
				vparallelGroup6.addComponent(bootsLabel);
				vparallelGroup6.addComponent(bootsBox);
				vparallelGroup7.addComponent(weaponLabel);
				vparallelGroup7.addComponent(weaponBox);
				vparallelGroup8.addComponent(shieldLabel);
				vparallelGroup8.addComponent(shieldBox);
				vparallelGroup9.addComponent(necklaceLabel);
				vparallelGroup9.addComponent(necklaceBox);
				vparallelGroup10.addComponent(earringLabel);
				vparallelGroup10.addComponent(earringBox);
				vparallelGroup11.addComponent(ring1Label);
				vparallelGroup11.addComponent(ring1Box);
				vparallelGroup12.addComponent(ring2Label);
				vparallelGroup12.addComponent(ring2Box);
				
				
				verticalSeqGrp1.addGroup(vparallelGroup0);
				verticalSeqGrp1.addGroup(vparallelGroup1);
				verticalSeqGrp1.addGroup(vparallelGroup2);
				verticalSeqGrp1.addGroup(vparallelGroup3);
				verticalSeqGrp1.addGroup(vparallelGroup4);
				verticalSeqGrp1.addGroup(vparallelGroup5);
				verticalSeqGrp1.addGroup(vparallelGroup6);
				verticalSeqGrp1.addGroup(vparallelGroup7);
				verticalSeqGrp1.addGroup(vparallelGroup8);
				verticalSeqGrp1.addGroup(vparallelGroup9);
				verticalSeqGrp1.addGroup(vparallelGroup10);
				verticalSeqGrp1.addGroup(vparallelGroup11);
				verticalSeqGrp1.addGroup(vparallelGroup12);
				
				layout.setHorizontalGroup(horizontalSeqGrp1);  
				layout.setVerticalGroup(verticalSeqGrp1);
				
				
			}
		}
		
		public class PlayerStats extends JPanel{
			
			/**
			 * 
			 */
			private static final long serialVersionUID = -1751593961320753351L;
			
			public Hashtable<JLabel, String> playerStatLabels = null;
			public JLabel[] labels = null;
			
			public void updateText(){
				//SwingUtilities.updateComponentTreeUI(labels[i]);
				//System.out.println(s);
				
				labels[0].setText("Name: "+profile.getName());
				labels[1].setText("Level: "+profile.getLevel());
				labels[2].setText("Job: "+profile.getJob());
				labels[3].setText("Job Level: "+profile.getJLevel());
				labels[4].setText("Strength: "+profile.getStr());
				labels[5].setText("Vitality: "+profile.getVit());
				labels[6].setText("Agility: "+profile.getAgi());
				labels[7].setText("Intelligence: "+profile.getIntel());
				labels[8].setText("Wisdom: "+profile.getWis());
				labels[9].setText("Dexterity: "+profile.getDex());
				labels[10].setText("Luck: "+profile.getLuck());
				labels[11].setText("Total: "+profile.getTotal());
				labels[12].setText("Max HP: "+profile.getMaxHP());
				labels[13].setText("Max MP: "+profile.getMaxMP());
				labels[14].setText("P.Atk: "+profile.getPAtk());
				labels[15].setText("P.Def: "+profile.getPDef());
				labels[16].setText("Accuracy: "+profile.getAcc());
				labels[17].setText("Evasion: "+profile.getEvasion());
				labels[18].setText("Atk. Speed: "+profile.getAtkSpd());
				labels[19].setText("M.Atk: "+profile.getMAtk());
				labels[20].setText("M.Def: "+profile.getMDef());
				labels[21].setText("M.Accuracy: "+profile.getMAcc());
				labels[22].setText("M.Res: "+profile.getMRes());
				labels[23].setText("Movement Speed: "+profile.getMovSpd());
				labels[24].setText("HP Regen: "+profile.getHPRegen());
				labels[25].setText("MP Regen: "+profile.getMPRegen());
				labels[26].setText("Block Percentage: "+profile.getBlockPer());
				labels[27].setText("Critical Ratio: "+profile.getCriRatio());
				labels[28].setText("Cast Speed: "+profile.getCastSpd());
				labels[29].setText("Critical Power: "+profile.getCriPow());
				labels[30].setText("HP Recovery: "+profile.getHPRecov());
				labels[31].setText("MP Recovery: "+profile.getMPRecov());
				labels[32].setText("Block Defence: "+profile.getBlockDef());
				labels[33].setText("Recast: "+profile.getRecast());
				labels[34].setText("Max Weight: "+profile.getMaxWT());
				labels[35].setText("HP Recovery per Min: "+profile.getHPRecPerMin());
				labels[36].setText("MP Recovery per Min: "+profile.getMPRecPerMin());
			}
			
			
			PlayerStats(Profile profile){
				this.setLayout(null);
			
				JLabel name = new JLabel("Name: ");
				JLabel level = new JLabel("Level: ");
				JLabel job = new JLabel("Job: ");
				JLabel jLvl = new JLabel("Job Level: ");
				JLabel str = new JLabel("Strength: ");
				JLabel vit = new JLabel("Vitality: ");
				JLabel agi = new JLabel("Agility: ");
				JLabel intel = new JLabel("Intelligence: ");
				JLabel wis = new JLabel("Wisdom: ");
				JLabel dex = new JLabel("Dexterity: ");
				JLabel luck = new JLabel("Luck: ");
				JLabel total = new JLabel("Total: ");
				JLabel maxHP = new JLabel("Max HP: ");
				JLabel maxMP = new JLabel("Max MP: ");
				JLabel pAtk = new JLabel("P.Atk: ");
				JLabel pDef = new JLabel("P.Def: ");
				JLabel acc = new JLabel("Accuracy: ");
				JLabel evasion = new JLabel("Evasion: ");
				JLabel atkSpd = new JLabel("Atk. Speed: ");
				JLabel mAtk = new JLabel("M.Atk: ");
				JLabel mDef = new JLabel("M.Def: ");
				JLabel mAcc = new JLabel("M.Accuracy: ");
				JLabel mRes = new JLabel("M.Res: ");
				JLabel movSpd = new JLabel("Movement Speed: ");
				JLabel hpRegen = new JLabel("HP Regen: ");
				JLabel mpRegen = new JLabel("MP Regen: ");
				JLabel blockPer = new JLabel("Block Percentage: ");
				JLabel criRatio = new JLabel("Critical Ratio: ");
				JLabel castSpd = new JLabel("Cast Speed: ");
				JLabel criPow = new JLabel("Critical Power: ");
				JLabel hpRec = new JLabel("HP Recovery: ");
				JLabel mpRec = new JLabel("MP Recovery: ");
				JLabel blockDef = new JLabel("Block Defence: ");
				JLabel recast = new JLabel("Recast: ");
				JLabel maxWT = new JLabel("Max Weight: ");
				JLabel hpRecPerMin = new JLabel("HP Recovery per Min: ");
				JLabel mpRecPerMin = new JLabel("MP Recovery per Min: ");
				
				labels = new JLabel[37];
			
				labels[0] = name;
				labels[1] = level;
				labels[2] = job;
				labels[3] = jLvl;
				labels[4] = str;
				labels[5] = vit;
				labels[6] = agi;
				labels[7] = intel;
				labels[8] = wis;
				labels[9] = dex;
				labels[10] = luck;
				labels[11] = total;
				labels[12] = maxHP;
				labels[13] = maxMP;
				labels[14] = pAtk;
				labels[15] = pDef;
				labels[16] = acc;
				labels[17] = evasion;
				labels[18] = atkSpd;
				labels[19] = mAtk;
				labels[20] = mDef;
				labels[21] = mAcc;
				labels[22] = mRes;
				labels[23] = movSpd;
				labels[24] = hpRegen;
				labels[25] = mpRegen;
				labels[26] = blockPer;
				labels[27] = criRatio;
				labels[28] = castSpd;
				labels[29] = criPow;
				labels[30] = hpRec;
				labels[31] = mpRec;
				labels[32] = blockDef;
				labels[33] = recast;
				labels[34] = maxWT;
				labels[35] = hpRecPerMin;
				labels[36] = mpRecPerMin;
			
				playerStatLabels = new Hashtable<JLabel, String>();
			
				playerStatLabels.put(name, ("Name: "+profile.getName()));
				playerStatLabels.put(level, ("Level: "+profile.getLevel()));
				playerStatLabels.put(job, ("Job: "+profile.getJob()));
				playerStatLabels.put(jLvl, ("Job Level: "+profile.getJLevel()));
				playerStatLabels.put(str, ("Strength: "+profile.getStr()));
				playerStatLabels.put(vit, ("Vitality: "+profile.getVit()));
				playerStatLabels.put(agi, ("Agility: "+profile.getAgi()));
				playerStatLabels.put(intel, ("Intelligence: "+profile.getIntel()));
				playerStatLabels.put(wis, ("Wisdom: "+profile.getWis()));
				playerStatLabels.put(dex, ("Dexterity: "+profile.getDex()));
				playerStatLabels.put(luck, ("Luck: "+profile.getLuck()));
				playerStatLabels.put(total, ("Total: "+profile.getTotal()));
				playerStatLabels.put(maxHP, ("Max HP: "+profile.getMaxHP()));
				playerStatLabels.put(maxMP, ("Max MP: "+profile.getMaxMP()));
				playerStatLabels.put(pAtk, ("P.Atk: "+profile.getPAtk()));
				playerStatLabels.put(pDef, ("P.Def: "+profile.getPDef()));
				playerStatLabels.put(acc, ("Accuracy: "+profile.getAcc()));
				playerStatLabels.put(evasion, ("Evasion: "+profile.getEvasion()));
				playerStatLabels.put(atkSpd, ("Atk. Speed: "+profile.getAtkSpd()));
				playerStatLabels.put(mAtk, ("M.Atk: "+profile.getMAtk()));
				playerStatLabels.put(mDef, ("M.Def: "+profile.getMDef()));
				playerStatLabels.put(mAcc, ("M.Accuracy: "+profile.getMAcc()));
				playerStatLabels.put(mRes, ("M.Res: "+profile.getMRes()));
				playerStatLabels.put(movSpd, ("Movement Speed: "+profile.getMovSpd()));
				playerStatLabels.put(hpRegen, ("HP Regen: "+profile.getHPRegen()));
				playerStatLabels.put(mpRegen, ("MP Regen: "+profile.getMPRegen()));
				playerStatLabels.put(blockPer, ("Block Percentage: "+profile.getBlockPer()));
				playerStatLabels.put(criRatio, ("Critical Ratio: "+profile.getCriRatio()));
				playerStatLabels.put(castSpd, ("Cast Speed: "+profile.getCastSpd()));
				playerStatLabels.put(criPow, ("Critical Power: "+profile.getCriPow()));
				playerStatLabels.put(hpRec, ("HP Recovery: "+profile.getHPRecov()));
				playerStatLabels.put(mpRec, ("MP Recovery: "+profile.getMPRecov()));
				playerStatLabels.put(blockDef, ("Block Defence: "+profile.getBlockDef()));
				playerStatLabels.put(recast, ("Recast: "+profile.getRecast()));
				playerStatLabels.put(maxWT, ("Max Weight: "+profile.getMaxWT()));
				playerStatLabels.put(hpRecPerMin, ("HP Recovery per Min: "+profile.getHPRecPerMin()));
				playerStatLabels.put(mpRecPerMin, ("MP Recovery per Min: "+profile.getMPRecPerMin()));
			
				Insets insets = this.getInsets();
				Dimension size = level.getPreferredSize();
			
				int x1 = 0;
				int x2 = 150;
				int y = 5;
				int i = 0;
			
				for(int k=0; k<labels.length-2;k++){
					JLabel s = labels[k];
					this.add(s);
					labels[k].setText(playerStatLabels.get(s));
					size = s.getPreferredSize();
					if (i%2==0){
						s.setBounds(x1 + insets.left, y + insets.top,
							size.width+100, size.height);
					} else {
						s.setBounds(x2 + insets.left, y + insets.top,
							size.width+100, size.height);
						y += 20;
					}
					i++;
				}
			
				this.add(hpRecPerMin);
				this.add(mpRecPerMin);
			
				int r = 20*((labels.length)/2)+5;
				System.out.println(r);
				size = hpRecPerMin.getPreferredSize();
				hpRecPerMin.setBounds(x1 + insets.left, r + insets.top,
					size.width+100, size.height);
				size = mpRecPerMin.getPreferredSize();
				mpRecPerMin.setBounds(x1 + insets.left, r+20 + insets.top,
					size.width+100, size.height);
			
				labels[35].setText(playerStatLabels.get(hpRecPerMin));
				labels[36].setText(playerStatLabels.get(mpRecPerMin));
			}
		}
		
		private Container makePanel(Profile profle) throws IOException{
			profile = profle;
			JPanel backPanel = new JPanel();
			JPanel petTabPanel = new JPanel();
			JPanel showPlayerStatsPanel = new PlayerStats(profile);
			JPanel equipTabPanel = new EquipTab(profile, (PlayerStats) showPlayerStatsPanel);
			JPanel playerTabPanel = new PlayerTab(profile, (PlayerStats) showPlayerStatsPanel);
			//TODO fire events from setup panels to refresh stat panels
			//TODO attach action listener 
			JButton button1 = new JButton("This is a test");
			JButton button2 = new JButton("Button2");
			JTabbedPane setUpTabs = new JTabbedPane();
			JTabbedPane statTabs = new JTabbedPane();
			JTabbedPane showPetsStatsTab = new JTabbedPane();
			JPanel statPet1 = new JPanel();
			JPanel statPet2 = new JPanel();
			JPanel statPet3 = new JPanel();
			JPanel statPet4 = new JPanel();
			JPanel statPet5 = new JPanel();
			
			JLabel tField = new JLabel("HI");			
			JLabel equipment1 = new JLabel("Equipments");
			
			setUpTabs.setMaximumSize(new Dimension(250,600));
			
			equipTabPanel.add(equipment1);
			setUpTabs.addTab("Player", null, playerTabPanel, "Configure Player");
			setUpTabs.addTab("Equipment", null, equipTabPanel, "Character Equipments");
			setUpTabs.addTab("Pets", null, petTabPanel, "Configure Pets");
			
			showPetsStatsTab.addTab("Pet1", null, statPet1, "Statistics for Pet1");
			showPetsStatsTab.addTab("Pet2", null, statPet2, "Statistics for Pet2");
			showPetsStatsTab.addTab("Pet3", null, statPet3, "Statistics for Pet3");
			showPetsStatsTab.addTab("Pet4", null, statPet4, "Statistics for Pet4");
			showPetsStatsTab.addTab("Pet5", null, statPet5, "Statistics for Pet5");
			
			statTabs.addTab("Player Stats", null, showPlayerStatsPanel, "Statistics for Player");
			statTabs.addTab("Pets Stats", null, showPetsStatsTab, "Statistics for Pets");
			
			GroupLayout layout = new GroupLayout(backPanel);
			backPanel.setLayout(layout);
			
			layout.setAutoCreateGaps(true);
			layout.setAutoCreateContainerGaps(false);
				
			MouseListener mouseListen = new MouseEventSetUp();
			button1.addMouseListener(mouseListen);
			button2.addMouseListener(new MouseEventSetUp());
			
			GroupLayout.SequentialGroup horizontalSeqGrp1 = layout.createSequentialGroup();  
			GroupLayout.SequentialGroup verticalSeqGrp1 = layout.createSequentialGroup();
			
			GroupLayout.ParallelGroup hParallelGroup1 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);  
			GroupLayout.ParallelGroup hParallelGroup2 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
			
			hParallelGroup1.addComponent(setUpTabs);
			hParallelGroup2.addComponent(statTabs);
			
			
			horizontalSeqGrp1.addGroup(hParallelGroup1);  
			horizontalSeqGrp1.addGroup(hParallelGroup2);
			
			GroupLayout.ParallelGroup vparallelGroup1 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
			GroupLayout.ParallelGroup vparallelGroup2 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
			
			vparallelGroup1.addComponent(setUpTabs);
			vparallelGroup1.addComponent(statTabs);
			
			verticalSeqGrp1.addGroup(vparallelGroup1);
			//verticalSeqGrp1.addGroup(vparallelGroup2);
			
			layout.setHorizontalGroup(horizontalSeqGrp1);  
			layout.setVerticalGroup(verticalSeqGrp1);
			
			return backPanel;
		}
		
		public Container getPanel(Profile profile) throws IOException{
			return makePanel(profile);
		}
	}
}
